package com.feeyo.groundservice.composewidget.view.divider

import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.material3.DividerDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.unit.Dp
import com.feeyo.groundservice.composewidget.R
import com.feeyo.groundservice.composewidget.util.toComposeColor

/**
 *作者：QLH on 2024-10-23
 *描述：线条,扩展系统的，可以定义渐变色的分割线
 */

@Composable
fun HorizontalDivider(
    modifier: Modifier = Modifier,
    thickness: Dp = DividerDefaults.Thickness,
    brush: Brush = Brush.horizontalGradient(listOf(R.color.black_33.toComposeColor()))
) =
    Canvas(modifier.fillMaxWidth().height(thickness)) {
        drawLine(
            brush = brush,
            strokeWidth = thickness.toPx(),
            start = Offset(0f, thickness.toPx() / 2),
            end = Offset(size.width, thickness.toPx() / 2),
        )
    }


@Composable
fun VerticalDivider(
    modifier: Modifier = Modifier,
    thickness: Dp = DividerDefaults.Thickness,
    brush: Brush = Brush.verticalGradient(listOf(R.color.black_33.toComposeColor()))
) =
    Canvas(modifier.fillMaxHeight().width(thickness)) {
        drawLine(
            brush = brush,
            strokeWidth = thickness.toPx(),
            start = Offset(thickness.toPx() / 2, 0f),
            end = Offset(thickness.toPx() / 2, size.height),
        )
    }